/*
 * homeDepot.cc
 */

#include "homedepot.h"
#include "locks.h"
#include "sharedDefinitions.h"

Store::Store(Locks* theLocks) {
    AllTheLocks = theLocks;
}

Store::~Store() {
}


void
Store::CreateAisles() {
}

/* Implemented by peskanda
 * Given an item ID, this will return its corresponding aisle number.
 * Customers will call this directly 75% of times,
 * 25% of the times, customer needs to wait for a stock boy so he can call
 * this function.
 */
int Store::GetAisleNumber(int itemIDNumber){
	ASSERT (AllTheLocks != NULL);
	ASSERT (itemIDNumber >=0 && itemIDNumber <= MAX_ITEMS);
	ASSERT (AllTheLocks->itemsInStore != NULL);
	//We just need to directly read the item and return its aisle number
	//We don't need locking in here because items list has been already created and will never change (read only)
	return AllTheLocks->itemsInStore[itemIDNumber]->getAisle();
}

bool Store::PickupItem(int itemIDNumber){
	ASSERT (AllTheLocks != NULL);
	ASSERT (itemIDNumber >=0 && itemIDNumber <= MAX_ITEMS);
	ASSERT (AllTheLocks->itemsInStore != NULL);
	//We just need to directly read the item and return its aisle number
	//We don't need locking in here because items list has been already created and will never change (read only)
	if (AllTheLocks->itemsInStore[itemIDNumber]->getQuantity() > 0)
	{
		AllTheLocks->itemsInStore[itemIDNumber]->DecreaseQuantity();
		return true;
	}
	return false;
}

bool Store::RestockItem(int itemIDNumber){
	ASSERT (AllTheLocks != NULL);
	ASSERT (itemIDNumber >=0 && itemIDNumber <= MAX_ITEMS);
	ASSERT (AllTheLocks->itemsInStore != NULL);
	//We just need to directly read the item and return its aisle number
	//We don't need locking in here because items list has been already created and will never change (read only)
	AllTheLocks->itemsInStore[itemIDNumber]->IncreaseQuantity();
	return true;
}

Locks* Store::GetAllTheLocks()
{
	return AllTheLocks;
}
